/**
 * Copyright (c) 2009-2011, chunquedong(YangJiandong)
 * 
 * This file is part of ChunMap project
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
 * 
 * History:
 *     2010-05-05  Jed Young  Creation
 */
package chunmap.example;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import chunmap.app.MapCtrl;
import chunmap.app.command.ExtentCommand;
import chunmap.app.tools.navigate.ZoomInBoxTool;

public class UiUtil {
	protected static void addCommonButton(Container frame,final MapCtrl map){
		UiUtil.addButton(frame,map,"全图",new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				map.executeCommand(new ExtentCommand(map,map.getLayerCollection().getEnvelop()));
				map.refreshMap();
			}
		});
		
		UiUtil.addButton(frame,map,"<=",new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				map.undo();
				map.refreshMap();
			}
		});
		
		UiUtil.addButton(frame,map,"=>",new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				map.redo();
				map.refreshMap();
			}
		});
		
		UiUtil.addButton(frame,map,"拉框放大",new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				map.setCurrentPlug(new ZoomInBoxTool());
			}
		});
	}
	
	public static void addButton(Container frame,final MapCtrl map
			,String text,ActionListener listener){
		JButton button = new JButton();
		button.setText(text);
		button.addActionListener(listener);
		frame.add(button);
	}
}